package cn.zcf.order.controller;

import cn.zcf.basic.utils.JsonResult;
import cn.zcf.basic.utils.PageList;
import cn.zcf.order.domain.OrderPet;
import cn.zcf.order.dto.OrderPetDto;
import cn.zcf.order.query.OrderPetQuery;
import cn.zcf.order.service.IOrderPetService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/orderPetAcquisition")
public class OrderPetController {
    @Autowired
    private IOrderPetService orderPetService;
    @PostMapping
    public PageList<OrderPet> pageQuery(@RequestBody OrderPetQuery query, HttpServletRequest request){
        try {
            return orderPetService.pageQuery(query,request);
        } catch (Exception e) {
            e.printStackTrace();
            return new PageList<OrderPet>();
        }

    }
    @PostMapping("/confirm")
    public JsonResult confirm(@RequestBody OrderPetDto dto){
        try {
            orderPetService.confirm(dto);
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("确认订单失败");
        }

    }
    @DeleteMapping("/{id}")
    @ApiOperation(value = "通过ID删除" )
    public JsonResult delete(@PathVariable("id") Long id){
        try {
            orderPetService.remove(id);
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("删除失败");
        }
    }
}
